package com.ddtech.framework.security.rest;

import com.ddtech.framework.security.security.LockUser;
import com.ddtech.framework.security.service.LockUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * <p>锁定用户控制器
 * </p>
 *
 * @author bin_pu
 * @since 2020/5/6 13:57
 */
@Api(tags = "系统-锁定用户管理")
@RestController
@RequestMapping("/auth/")
public class LockUserController {

    @Autowired
    private LockUserService lockUserService;

    @ApiOperation("查询锁定用户")
    @GetMapping(value = "/lockUserAll")
    @PreAuthorize("hasAnyRole('ADMIN','LOCK_ALL','LOCK_SELECT')")
    public ResponseEntity lockAll(String filter, Pageable pageable) {
        return new ResponseEntity<>(lockUserService.getAll(filter, pageable), HttpStatus.OK);
    }

    @ApiOperation("锁定用户解锁")
    @PostMapping(value = "/unLockUser")
    @PreAuthorize("hasAnyRole('ADMIN','LOCK_ALL','LOCK_DELETE')")
    public ResponseEntity unLock(LockUser lockUser) throws Exception {
        lockUserService.unLock(lockUser);
        return new ResponseEntity(HttpStatus.OK);
    }

}
